package com.ruoyi.web.shopping.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.shopping.dto.DiscountMaxDTO;
import com.ruoyi.web.shopping.dto.ProductsDTO;
import com.ruoyi.web.shopping.dto.SaleDTO;
import com.ruoyi.web.shopping.service.SaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/sale")
@Slf4j
@Api(tags = "销售额相关接口")
public class SaleController {

    @Autowired
    private SaleService saleService;

    /**
     * 通过活动名称查询销售额
     *
     * @param disName
     * @return
     */
    @GetMapping("/{disName}")
    @ApiOperation("通过活动名称查询销售额")
    public R<ArrayList<SaleDTO>> selectByName(@PathVariable String disName) {
        log.info("查询商品名称为：{}", disName);
        ArrayList<SaleDTO> saleDTOs = saleService.selectByName(disName);
        return R.ok(saleDTOs);
    }

    /**
     * 查询销售额最高
     *
     * @return
     */
    @GetMapping("/max")
    @ApiOperation("查询销售额最高")
    public R<DiscountMaxDTO> selectMax() {
        DiscountMaxDTO discountMaxDTO = saleService.selectMax();
        return R.ok(discountMaxDTO);
    }
}
